﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WSSaiGon
{
    public partial class Invoker : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnCall_Click(object sender, EventArgs e)
        {

            {
                //Getting parameter
                //Param 1
                object x1 = null;
                switch (ddlType1.SelectedValue)
                {
                    case "0":
                        x1 = Convert.ToInt32(txtInput1.Text);
                        break;
                    case "1":
                        x1 = txtInput1.Text;
                        break;
                    case "2":
                        x1 = Convert.ToBoolean(txtInput1.Text);
                        break;
                    case "3":
                        x1 = Convert.ToDouble(txtInput1.Text);
                        break;
                }

                //Param 2
                object x2 = null;
                switch (ddlType2.SelectedValue)
                {
                    case "0":
                        x2 = Convert.ToInt32(txtInput2.Text);
                        break;
                    case "1":
                        x2 = txtInput2.Text;
                        break;
                    case "2":
                        x2 = Convert.ToBoolean(txtInput2.Text);
                        break;
                    case "3":
                        x2 = Convert.ToDouble(txtInput2.Text);
                        break;
                }

                //Param 3
                object x3 = null;
                switch (ddlType3.SelectedValue)
                {
                    case "0":
                        x3 = Convert.ToInt32(txtInput3.Text);
                        break;
                    case "1":
                        x3 = txtInput3.Text;
                        break;
                    case "2":
                        x3 = Convert.ToBoolean(txtInput3.Text);
                        break;
                    case "3":
                        x3 = Convert.ToDouble(txtInput3.Text);
                        break;
                }

                //Param 4
                object x4 = null;
                switch (ddlType4.SelectedValue)
                {
                    case "0":
                        x4 = Convert.ToInt32(txtInput4.Text);
                        break;
                    case "1":
                        x4 = txtInput4.Text;
                        break;
                    case "2":
                        x4 = Convert.ToBoolean(txtInput4.Text);
                        break;
                    case "3":
                        x4 = Convert.ToDouble(txtInput4.Text);
                        break;
                }

                //Param 5
                object x5 = null;
                switch (ddlType5.SelectedValue)
                {
                    case "0":
                        x5 = Convert.ToInt32(txtInput5.Text);
                        break;
                    case "1":
                        x5 = txtInput5.Text;
                        break;
                    case "2":
                        x5 = Convert.ToBoolean(txtInput5.Text);
                        break;
                    case "3":
                        x5 = Convert.ToDouble(txtInput5.Text);
                        break;
                }

                //Param 6
                object x6 = null;
                switch (ddlType6.SelectedValue)
                {
                    case "0":
                        x6 = Convert.ToInt32(txtInput6.Text);
                        break;
                    case "1":
                        x6 = txtInput6.Text;
                        break;
                    case "2":
                        x6 = Convert.ToBoolean(txtInput6.Text);
                        break;
                    case "3":
                        x6 = Convert.ToDouble(txtInput6.Text);
                        break;
                }

                //Param 7
                object x7 = null;
                switch (ddlType7.SelectedValue)
                {
                    case "0":
                        x7 = Convert.ToInt32(txtInput7.Text);
                        break;
                    case "1":
                        x7 = txtInput7.Text;
                        break;
                    case "2":
                        x7 = Convert.ToBoolean(txtInput7.Text);
                        break;
                    case "3":
                        x7 = Convert.ToDouble(txtInput7.Text);
                        break;
                }

                //Param 8
                object x8 = null;
                switch (ddlType8.SelectedValue)
                {
                    case "0":
                        x8 = Convert.ToInt32(txtInput8.Text);
                        break;
                    case "1":
                        x8 = txtInput8.Text;
                        break;
                    case "2":
                        x8 = Convert.ToBoolean(txtInput8.Text);
                        break;
                    case "3":
                        x8 = Convert.ToDouble(txtInput8.Text);
                        break;
                }

                //Param 9
                object x9 = null;
                switch (ddlType9.SelectedValue)
                {
                    case "0":
                        x9 = Convert.ToInt32(txtInput9.Text);
                        break;
                    case "1":
                        x9 = txtInput9.Text;
                        break;
                    case "2":
                        x9 = Convert.ToBoolean(txtInput9.Text);
                        break;
                    case "3":
                        x9 = Convert.ToDouble(txtInput9.Text);
                        break;
                }

                //Param 10
                object x10 = null;
                switch (ddlType10.SelectedValue)
                {
                    case "0":
                        x10 = Convert.ToInt32(txtInput10.Text);
                        break;
                    case "1":
                        x10 = txtInput10.Text;
                        break;
                    case "2":
                        x10 = Convert.ToBoolean(txtInput10.Text);
                        break;
                    case "3":
                        x10 = Convert.ToDouble(txtInput10.Text);
                        break;
                }

                //Param 11
                object x11 = null;
                switch (ddlType11.SelectedValue)
                {
                    case "0":
                        x11 = Convert.ToInt32(txtInput11.Text);
                        break;
                    case "1":
                        x11 = txtInput11.Text;
                        break;
                    case "2":
                        x11 = Convert.ToBoolean(txtInput11.Text);
                        break;
                    case "3":
                        x11 = Convert.ToDouble(txtInput11.Text);
                        break;
                }
                //End of getting params

                int x = Convert.ToInt32(numberofParams.SelectedItem.Text);

                object[] param = new object[0];
                switch (x)
                {
                    case 1:
                        param = new object[] { x1 };
                        break;
                    case 2:
                        param = new object[] { x1, x2 };
                        break;
                    case 3:
                        param = new object[] { x1, x2, x3 };
                        break;
                    case 4:
                        param = new object[] { x1, x2, x3, x4 };
                        break;
                    case 5:
                        param = new object[] { x1, x2, x3, x4, x5 };
                        break;
                    case 6:
                        param = new object[] { x1, x2, x3, x4, x5, x6 };
                        break;
                    case 7:
                        param = new object[] { x1, x2, x3, x4, x5, x6, x7 };
                        break;
                    case 8:
                        param = new object[] { x1, x2, x3, x4, x5, x6, x7, x8 };
                        break;
                    case 9:
                        param = new object[] { x1, x2, x3, x4, x5, x6, x7, x8, x9 };
                        break;
                    case 10:
                        param = new object[] { x1, x2, x3, x4, x5, x6, x7, x8, x9, x10 };
                        break;
                    case 11:
                        param = new object[] { x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11 };
                        break;
                }
                string abc = "adf";
                string ds = "ds";
                object result = null;
                result = WebserviceInvoker
                                .WSInvoker
                                .CallWebService(txtLinkWS.Text, txtServiceName.Text, txtMethod.Text, param);
                if (lblResult.Text != "")
                    lblResult.Text = "Result: ";
                lblResult.Text += "<br/>" + result.ToString();

                // arg4 => string 
                ddlReturnType.SelectedValue = "string";
            }
            //catch
            {
                //lblResult.Text = "Please fill all fields, check all checkbox, and select correct data types";
            }
        }
    }
}